#!/bin/bash
set -e  # Exit immediately if a command exits with a non-zero status.

DIR=$1
PKG=$2

rm -rf ~/rpmbuild/
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
cp $DIR/$PKG/$PKG/* ~/rpmbuild/SOURCES/
mv ~/rpmbuild/SOURCES/*.spec ~/rpmbuild/SPECS/
rpmbuild -bs ~/rpmbuild/SPECS/*.spec

# 依赖server上运行的nginx http服务，并且有对应的路由
# TODO: 解决硬编码，从配置文件读入
cp ~/rpmbuild/SRPMS/*.src.rpm /usr/share/nginx/html/files
# cd /usr/share/nginx/html/files
# koji mock-config --tag dist-ocs23-build -a x86_64 > mock.cfg